//
//  FMAlbum.m
//  DolphinMusic
//
//  Created by dllo on 15/3/26.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "FMAlbum.h"

@implementation FMAlbum

 -(void)dealloc
{
    [_lastTrackDate release];
    [_albumID release];
    [_title release];
    [_albumCoverUrl290 release];
    [_playCounts release];
    [_trackCounts release];
    [super dealloc];
}

- (instancetype)initWithDictionary:(NSDictionary *)dic
{
    self = [super init];
    if (self) {
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    if ([key isEqualToString:@"id"]) {
        NSNumber *num1 = value;
        self.albumID = [num1 stringValue];
    }
    if ([key isEqualToString:@"playsCounts"]) {
        NSNumber *num2 = value;
        self.playCounts = [NSString stringWithFormat:@"%.1f万",[num2 floatValue] / 10000];
        if ([value integerValue] < 10000) {
            self.playCounts = [NSString stringWithFormat:@"%ld", [value integerValue]];
        }
    }
    if ([key isEqualToString:@"tracksCounts"]) {
        self.trackCounts = [value stringValue];
    }
    if ([key isEqualToString:@"lastUptrackAt"]) {
        
        NSInteger a = [value integerValue] / 1000;
        NSDate *date = [NSDate dateWithTimeIntervalSince1970:a];
        NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
        [formatter setDateFormat:@"yyyy-MM-dd"];
        self.lastTrackDate = [formatter stringFromDate:date];
        if (a < 100000000) {
            NSDate *localDate = [NSDate dateWithTimeIntervalSinceNow:28800];
            self.lastTrackDate = [formatter stringFromDate:localDate];
        }
    }
    
}

- (id)valueForUndefinedKey:(NSString *)key
{
    return nil;
}

@end
